package is;

import is.model.exceptions.EmptyValueException;
import is.web.Locale;

/**
 *
 * @author aspr0
 */
public class NullUtil
{
    public static String toString(Object o)
    {
        return (o == null) ? "" : o.toString();
    }

    /**
     * Proves if object's null
     *
     * @param o
     * @throws EmptyValueException
     */
    public static void prove(Object o) throws EmptyValueException
    {
        if (o == null)
        {
            throw new EmptyValueException();
        }
    }

    public static String concat(String... strings)
    {
        String output = "";
        String delimiter = " ";

        for (String s : strings)
        {
            if (s == null)
            {
                return Locale.NULL;
            }
            else
            {
                output += s + delimiter;
            }
        }

        return output;
    }

    public static String toLink(String canvas, Integer id, String text)
    {
        if (id == 0 || text == null)
        {
            return Locale.NULL;
        }
        return String.format(canvas, id, text);
    }
}
